﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Data.Caching;

namespace MDCAdminTool
{
    public static class CacheClientFactory
    {
        public static DataCache GetCache( MdcCache cache )
        {
            return GetCache( cache.Name , "localhost" , cache.Parent.CachePort , cache.Parent.ServiceName );
        }
        public static DataCache GetCache( string cacheName , string serverName , int port , string serviceName )
        {
            var endpoints = new[] { new DataCacheServerEndpoint( serverName , port , serviceName ?? "DistributedCacheService" ) };

            DataCacheFactory.DisableLogSinks();

            try
            {
                var dcf = new DataCacheFactory( endpoints , false , false );

                var dcc = dcf.GetCache( cacheName );

                return dcc;
            }
            catch ( Exception ex )
            {
            }

            return null;
        }
    }
}
